package com.tablepet.activities.main;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.tablepet.R;
import com.tablepet.adapter.ShopAdapter;
import com.tablepet.bean.ShopBean;
import com.tablepet.databinding.FragmentShopBinding;
import com.tablepet.utils.swipe.CardConfig;
import com.tablepet.utils.swipe.SwipeCardCallback;

import java.util.ArrayList;
import java.util.List;

public class ShopFragment extends Fragment {
    private FragmentShopBinding binding;
    private final List<ShopBean> data=new ArrayList<>(),data1=new ArrayList<>(),data2=new ArrayList<>();;;

    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = FragmentShopBinding.inflate(inflater, container, false);
        CardConfig.initConfig(requireContext());


        requireActivity().runOnUiThread(() -> {
            binding.shopNewArrivals.setLayoutManager(new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL,false));
            binding.shopNewArrivals.setAdapter(new ShopAdapter(data));
            new ItemTouchHelper(new SwipeCardCallback(binding.shopNewArrivals, binding.shopNewArrivals.getAdapter(),data)).attachToRecyclerView(binding.shopNewArrivals);
            data.add(new ShopBean(R.drawable.button1,"sale condition","pet‘s name"));
            data.add(new ShopBean(R.drawable.logo,"sale condition","pet‘s name"));
            data.add(new ShopBean(R.drawable.button1,"sale condition","pet‘s name"));
            data.add(new ShopBean(R.drawable.logo,"sale condition","pet‘s name"));
            binding.shopNewArrivals.getAdapter().notifyDataSetChanged();


            binding.shopPopular.setLayoutManager(new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL,false));
            binding.shopPopular.setAdapter(new ShopAdapter(data1));
            new ItemTouchHelper(new SwipeCardCallback(binding.shopPopular, binding.shopPopular.getAdapter(),data1)).attachToRecyclerView(binding.shopPopular);
            data1.add(new ShopBean(R.drawable.button2,"sale condition","pet‘s name"));
            data1.add(new ShopBean(R.drawable.logo,"sale condition","pet‘s name"));
            data1.add(new ShopBean(R.drawable.button2,"sale condition","pet‘s name"));
            data1.add(new ShopBean(R.drawable.logo,"sale condition","pet‘s name"));
            data1.add(new ShopBean(R.drawable.button2,"sale condition","pet‘s name"));
            binding.shopPopular.getAdapter().notifyDataSetChanged();


            binding.shopSellingFast.setLayoutManager(new LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL,false));
            binding.shopSellingFast.setAdapter(new ShopAdapter(data2));
            new ItemTouchHelper(new SwipeCardCallback(binding.shopSellingFast, binding.shopSellingFast.getAdapter(),data2)).attachToRecyclerView(binding.shopSellingFast);
            data2.add(new ShopBean(R.drawable.button3,"sale condition","pet‘s name"));
            data2.add(new ShopBean(R.drawable.logo,"sale condition","pet‘s name"));
            data2.add(new ShopBean(R.drawable.button3,"sale condition","pet‘s name"));
            data2.add(new ShopBean(R.drawable.logo,"sale condition","pet‘s name"));
            data2.add(new ShopBean(R.drawable.button3,"sale condition","pet‘s name"));
            binding.shopSellingFast.getAdapter().notifyDataSetChanged();
        });




        return binding.getRoot();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}